package Druid;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;

/**
 * 关于Druid连接池的使用
 *
 * @author Mc.Chai
 * @program: JavaWeb
 * @create 2021-12-16-19:21 19:21
 */
public class DruidDemo {
    public static void main(String[] args) throws Exception {
        //1.导入jar包      -->libs/druid-1.1.12.jar
        //2.自定义配置文件  -->druid.properties
        //3.加载配置文件
        Properties properties = new Properties();
        InputStream resourceAsStream = DruidDemo.class.getClassLoader().getResourceAsStream("druid.properties");
        properties.load(resourceAsStream);
        //4.获取连接池对象
        DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
        //5.获取连接
        Connection connection = dataSource.getConnection();
        System.out.println(connection);
    }
}
